home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-07-08 | 9.1 KB | 350 lines | [TEXT/PJMM] |
- unit Routines;
- interface
- type
- TriMenuPanels = array[1..2, 1..1] of Rect;
- const
- Frame = False;
- var
- Screen, HArrow, HArrowMask, VArrow, VArrowMask, VirginPort: GrafPtr;
- Place, PlaceII: Rect;
- ArrowDown, WasInQ, WasInA: Boolean;
- TriMenu: TriMenuPanels;
- RightPanel: Integer;
-
- function CreateOSPort (BitRect: Rect): GrafPtr;
- procedure WindowInit;
- procedure LoademUp;
- procedure GetPictSize (EyeD1: integer; var Size: Rect);
- procedure PrepArrows;
- procedure DrawFirstArrow;
- procedure DoEvents;
- function InRect (R1: Rect; P: Point): Boolean;
- procedure DownTri;
- procedure UpTri;
- procedure DrawTriMenu;
- procedure DoAbout;
- procedure DoQuit;
- procedure TraceMouse;
-
- implementation
- function CreateOSPort (BitRect: Rect): GrafPtr;
- var
- OffScreen: GrafPtr;
- BaseAddr: Ptr;
- Rowbytes: integer;
- begin
- GetPort(Screen);
- OffScreen := GrafPtr(NewPtr(Sizeof(GrafPort)));
- if (Offscreen <> nil) then
- begin
- OpenPort(Offscreen);
- Rowbytes := ((BitRect.Right - BitRect.Left + 15) div 16) * 2;
- BaseAddr := NewPtr(Rowbytes * Longint((BitRect.Bottom - BitRect.Top)));
- if (BaseAddr <> nil) then
- begin
- OffScreen^.PortBits.Rowbytes := RowBytes;
- OffScreen^.PortBits.BaseAddr := BaseAddr;
- OffScreen^.PortRect := BitRect;
- OffScreen^.PortBits.Bounds := BitRect;
- RectRgn(OffScreen^.ClipRgn, BitRect);
- RectRgn(OffScreen^.VisRgn, BitRect);
- end
- else
- begin
- ClosePort(OffScreen);
- DisposePtr(Ptr(Offscreen));
- OffScreen := nil;
- end;
- end;
- EraseRect(OffScreen^.PortBits.Bounds);
- SetPort(Screen);
- CreateOSPort := OffScreen;
- end;
- {****************************************************************************}
- procedure WindowInit;
- var
- HelloWindow: WindowPtr;
- begin
- InitCursor;
- helloWindow := GetNewWindow(600, nil, Pointer(-1));
- ShowWindow(HelloWindow);
- SetPort(HelloWindow);
- end;
- {****************************************************************************}
- procedure GetPictSize (EyeD1: integer; var Size: Rect);
- var
- Picture: PicHandle;
- begin
- Picture := GetPicture(EyeD1);
- Size := Picture^^.PicFrame;
- end;
- {****************************************************************************}
- procedure PrepArrows;
- var
- Size: Rect;
- begin
- GetPictSize(10000, Size);
- HArrow := CreateOSPort(Size);
- GetPictSize(10001, Size);
- HArrowMask := CreateOSPort(Size);
- GetPictSize(10002, Size);
- VArrow := CreateOSPort(Size);
- GetPictSize(10003, Size);
- VArrowMask := CreateOSPort(Size);
- with Size do
- begin
- Right := Right + 1;
- Left := Left + 1;
- Top := Top + 1;
- Bottom := Bottom + 1;
- end;
- VirginPort := CreateOSPort(Size);
- LoademUp;
- end;
- {****************************************************************************}
- procedure LoademUp;
- var
- Picture: PicHandle;
- A, B: integer;
- begin
- for A := 0 to 3 do
- begin
- B := 10000 + A;
- Picture := GetPicture(B);
- case A of
- 0:
- begin
- SetPort(HArrow);
- DrawPicture(Picture, HArrow^.PortBits.Bounds);
- end;
- 1:
- begin
- SetPort(HArrowMask);
- DrawPicture(Picture, HArrowMask^.PortBits.Bounds);
- end;
- 2:
- begin
- SetPort(VArrow);
- DrawPicture(Picture, VArrow^.PortBits.Bounds);
- end;
- 3:
- begin
- SetPort(VArrowMask);
- DrawPicture(Picture, VArrowMask^.PortBits.Bounds);
- end;
- end;{Case Statement}
- end;
- SetPort(Screen);
- end;
- {****************************************************************************}
- procedure DrawFirstArrow;
- var
- Dummy: Longint;
- AboutSize, QuitSize: Rect;
- begin
- SetRect(Place, 50, 50, 58, 63);
- SetRect(PlaceII, 46, 53, 59, 61);
- ArrowDown := false;
- CopyMask(HArrow^.PortBits, HArrowMask^.PortBits, Screen^.PortBits, HArrow^.PortBits.Bounds, HArrowMask^.PortBits.Bounds, Place);
- MoveTo(65, 61);
- TextSize(10);
- DrawString('Tri-Menu');
- RightPanel := StringWidth('Tri-Menu');
- SetRect(AboutSize, 83, 68, 65 + RightPanel, 80);
- SetRect(QuitSize, 83, 83, 65 + RightPanel, 95);
- TriMenu[1, 1] := AboutSize;
- TriMenu[2, 1] := QuitSize;
- end;
- {****************************************************************************}
- procedure DoEvents;
- var
- GotOne, InTri, InAbout, InQuit: Boolean;
- TheEvent: EventRecord;
- TheChar: Char;
- begin
- GotOne := false;
- repeat
- GotOne := WaitNextEvent(EveryEvent, TheEvent, 60, nil);
- if (ArrowDown = true) then
- TraceMouse;
- until GotOne;
- case TheEvent.What of
- MouseDown:
- begin
- if (ArrowDown = false) then
- begin
- GlobalToLocal(TheEvent.Where);
- InTri := InRect(Place, TheEvent.Where);
- if (InTri = true) then
- DownTri;
- end;
- if (ArrowDown = true) then
- begin
- GlobalToLocal(TheEvent.Where);
- InTri := InRect(PlaceII, TheEvent.Where);
- if (InTri = true) then
- UpTri
- else
- begin
- InAbout := InRect(TriMenu[1, 1], TheEvent.Where);
- if (InAbout = true) then
- DoAbout
- else
- begin
- InQuit := InRect(TriMenu[2, 1], TheEvent.Where);
- if (InQuit = true) then
- DoQuit;
- end;{InQuit}
- end;{NotInTri}
- end;{ArrowDown = true}
- end;{MouseDown Case}
- KeyDown, AutoKey:
- begin
- TheChar := CHR(BitAnd(TheEvent.Message, CharCodeMask));
- if (TheChar = 'Q') or (TheChar = 'q') then
- Halt;
- end;
- otherwise
- begin
- end;
- end;{Case statement}
- end;
- {****************************************************************************}
- function InRect (R1: Rect; P: Point): Boolean;
- var
- number: integer;
- begin
- with P, R1 do
- begin
- if (H > Left) and (H < Right) and (V > Top) and (V < Bottom) then
- InRect := true
- else
- InRect := false;
- end;
- end;
- {****************************************************************************}
- procedure DownTri;
- var
- Dummy: Longint;
- begin
- ArrowDown := True;
- CopyMask(HArrowMask^.PortBits, HArrowMask^.PortBits, Screen^.PortBits, HArrow^.PortBits.Bounds, HArrowMask^.PortBits.Bounds, Place);
- Delay(10, Dummy);
- CopyBits(VirginPort^.PortBits, Screen^.PortBits, VirginPort^.PortBits.Bounds, Place, 0, nil);
- CopyMask(VArrowMask^.PortBits, VArrowMask^.PortBits, Screen^.PortBits, VArrow^.PortBits.Bounds, VArrowMask^.PortBits.Bounds, PlaceII);
- Delay(30, Dummy);
- CopyMask(VArrow^.PortBits, VArrowMask^.PortBits, Screen^.PortBits, VArrow^.PortBits.Bounds, VArrowMask^.PortBits.Bounds, PlaceII);
- DrawTriMenu;
- end;
- {****************************************************************************}
- procedure UpTri;
- var
- Dummy: Longint;
- ClearMenu: Rect;
- begin
- SetRect(ClearMenu, 65, TriMenu[1, 1].Top, 66 + RightPanel, TriMenu[2, 1].bottom);
- ArrowDown := false;
- CopyMask(VArrowMask^.PortBits, VArrowMask^.PortBits, Screen^.PortBits, VArrow^.PortBits.Bounds, VArrowMask^.PortBits.Bounds, PlaceII);
- Delay(10, Dummy);
- CopyBits(VirginPort^.PortBits, Screen^.PortBits, VirginPort^.PortBits.Bounds, PlaceII, 0, nil);
- CopyMask(HArrowMask^.PortBits, HArrowMask^.PortBits, Screen^.PortBits, HArrow^.PortBits.Bounds, HArrowMask^.PortBits.Bounds, Place);
- Delay(30, Dummy);
- EraseRect(ClearMenu);
- CopyMask(HArrow^.PortBits, HArrowMask^.PortBits, Screen^.PortBits, HArrow^.PortBits.Bounds, HArrowMask^.PortBits.Bounds, Place);
- end;
- {****************************************************************************}
- procedure DrawTriMenu;
- var
- StringLength: integer;
- begin
- if (Frame = True) then
- begin
- FrameRect(TriMenu[1, 1]);
- FrameRect(TriMenu[2, 1]);
- end;
- StringLength := StringWidth('About ');
- MoveTo(85, 78);
- DrawString('About');
- StringLength := StringWidth('Quit ');
- MoveTo(85, 93);
- DrawString('Quit');
- end;
- {****************************************************************************}
- procedure DoQuit;
- begin
- Halt;
- end;
- {****************************************************************************}
- procedure TraceMouse;
- var
- InAbout, InQuit: boolean;
- Location: point;
- begin
- GetMouse(Location);
- InAbout := InRect(TriMenu[1, 1], Location);
- InQuit := InRect(TriMenu[2, 1], Location);
- if (InQuit = false) and (WasInQ = true) then
- begin
- WasInQ := false;
- InvertRect(TriMenu[2, 1]);
- end;
- if (InAbout = True) then
- begin
- if (WasInA = false) then
- begin
- InvertRect(TriMenu[1, 1]);
- WasInA := True;
- WasInQ := false;
- end
- else
- begin
- end;
- end;{InAbout}
- if (InAbout = False) and (WasInA = true) then
- begin
- WasInA := false;
- InvertRect(TriMenu[1, 1]);
- end;
- if (InQuit = True) then
- begin
- if (WasInQ = false) then
- begin
- InvertRect(TriMenu[2, 1]);
- WasInQ := True;
- WasInA := false;
- end
- else
- begin
- end;
- end;{InQuit}
- end;
- {****************************************************************************}
- procedure DoAbout;
- var
- TheDialog: DialogPtr;
- DialogDone: boolean;
- ItemHit: integer;
- begin
- TheDialog := GetNewDialog(400, nil, WindowPtr(-1));
- ShowWindow(TheDialog);
- while DialogDone = False do
- begin
- ModalDialog(nil, ItemHit);
- case ItemHit of
- 2:
- begin
- Dialogdone := true;
- end;
- otherwise
- begin
- end;
- end;{Case}
- end;{While}
- HideWindow(TheDialog);
- end;
- end.
-
-
-
-
-